package com.ruoyi.web.controller.system;

import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CarCustomer;
import com.ruoyi.system.service.ICarCustomerService;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户信息Controller
 * 
 * @author ruoyi
 * @date 2024-09-09
 */
@RestController
//@Anonymous
@RequestMapping("/system/customer")
public class CarCustomerController extends BaseController {
	@Autowired
	private ICarCustomerService carCustomerService;

	/**
	 * 查询用户信息列表@DataScope
	 */
	@PreAuthorize("@ss.hasPermi('system:customer:list')")
	@GetMapping("/list")
	public TableDataInfo list(CarCustomer carCustomer) {
		//LoginUser loginUser=SecurityUtils.getLoginUser();
		startPage();
		List<CarCustomer> list = carCustomerService.selectCarCustomerList(carCustomer);
		return getDataTable(list);
	}

	/**
	 * 导出用户信息列表
	 */
	@PreAuthorize("@ss.hasPermi('system:customer:export')")
	@Log(title = "用户信息", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, CarCustomer carCustomer) {
		List<CarCustomer> list = carCustomerService.selectCarCustomerList(carCustomer);
		ExcelUtil<CarCustomer> util = new ExcelUtil<CarCustomer>(CarCustomer.class);
		util.exportExcel(response, list, "用户信息数据");
	}

	/**
	 * 获取用户信息详细信息
	 */
	@PreAuthorize("@ss.hasPermi('system:customer:query')")
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") Long id) {
		return success(carCustomerService.selectCarCustomerById(id));
	}

	/**
	 * 新增用户信息
	 */
	@PreAuthorize("@ss.hasPermi('system:customer:add')")
	@Log(title = "用户信息", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody CarCustomer carCustomer) {
		return toAjax(carCustomerService.insertCarCustomer(carCustomer));
	}

	/**
	 * 修改用户信息
	 */
	@PreAuthorize("@ss.hasPermi('system:customer:edit')")
	@Log(title = "用户信息", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody CarCustomer carCustomer) {
		return toAjax(carCustomerService.updateCarCustomer(carCustomer));
	}

	/**
	 * 删除用户信息
	 */
	@PreAuthorize("@ss.hasPermi('system:customer:remove')")
	@Log(title = "用户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable Long[] ids) {
		return toAjax(carCustomerService.deleteCarCustomerByIds(ids));
	}

	@GetMapping("/selectListByPage")
	public Object selectListByPage(@RequestParam("name") String name) {
		System.out.println(name);
		HashMap<String, String> hashMap = new HashMap<String, String>();
		hashMap.put("msg", "ok");
		return hashMap;
	}

	@PostMapping("/selectListByPage2")
	public Object selectListByPage2(@RequestBody HashMap<String, String> paramMap) {
		System.out.println(paramMap.get("name"));
		HashMap<String, String> hashMap = new HashMap<String, String>();
		hashMap.put("msg", "ok");
		return hashMap;
	}
	
    /**
     * 使用 PageHelper进行分页
     * @param tbTaskItemsVO 入参
     * @return 返回
     */
    @PostMapping("/getTaskItemsPage2")
    public PageInfo<CarCustomer> getTaskItems2(CarCustomer tbTaskItemsVO){
        PageHelper.startPage(1,1);
        List<CarCustomer> itemsList = carCustomerService.selectCarCustomerList(tbTaskItemsVO);
        PageInfo<CarCustomer> pageInfo = new PageInfo<>(itemsList);
        return pageInfo;
    }
    
    /**
	 * 新增用户信息
	 */
	//@PostMapping("/addOpen")
	public AjaxResult addOpen(@RequestBody CarCustomer carCustomer) {
		return toAjax(carCustomerService.insertCarCustomer(carCustomer));
	}
	
	
	/**
	 * 修改用户信息
	 */
	@PostMapping("/editOpen")
	public AjaxResult editOpen(@RequestBody CarCustomer carCustomer) {
		return toAjax(carCustomerService.updateCarCustomerByWxId(carCustomer));
	}
	/**
	 * 获取用户信息详细信息
	 */
	@PostMapping(value = "getInfoOpen")
	public AjaxResult getInfoOpen(@RequestBody CarCustomer carCustomer) {
		String wxId=carCustomer.getWxId();
		return success(carCustomerService.selectByWxId(wxId));
	}

}
